package simulation;

public class DayOfTheWeek1185 {
    //通过查询日历可知，1970 年 1212 月 31 日是星期四
    public String dayOfTheWeek(int day, int month, int year) {
        String[] Days = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        int[] months = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
        int days = 0;
        for (int i = 1971; i < year; i++) {
            if (isRun(i)) {
                days+=366;
            }else {
                days+=365;
            }
        }

        for (int i = 0; i < month-1; i++) {
            if(i==1&&isRun(year)){
                days+=1;
            }
            days+=months[i];
        }

        days+=day;

        int rest = (4+days)%7;
        return  Days[rest];
    }

    private boolean isRun(int year) {
        return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0));
    }
}
